//
//  JYMainTabBarController.swift
//  01.weibo
//
//  Created by 谢玉锋 on 16/7/8.
//  Copyright © 2016年 itheima.cn. All rights reserved.
//

import UIKit

class JYMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar = JYTabBar()
        
        //设置闭包
        
        //只读属性,不能直接用= 号赋值,使用KVC
        self.setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeClosure = { () -> Void in
            print("点击了加号按钮")
        }
        setupChildViewController()
    
    }
    
    private func setupChildViewController(){
        //首页
        setupChildController(JYHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        //消息
        setupChildController(JYMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        setupChildController(JYDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        //我
        setupChildController(JYProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
    }
    
    private func setupChildController(controller:UIViewController, imageName: String, title: String) {
        
        //设置tabBar图片
        controller.tabBarItem.image = UIImage(named:imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置title
        controller.title = title
        //设置标题颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        // 包装一个导航控制器,并添加到tabBarVC里面
        addChildViewController(UINavigationController(rootViewController: controller))
    
    }


}
